import { OnDestroy, OnInit, Component } from '@angular/core';
import { EzFormComponent } from '../ez-form';
import { EzFormControlComponent, EzFormControlConfiguration } from '../ez-form-control';
import { EzFormGroupComponent } from '../ez-form-group';
import { EzFormItemComponent } from '../ez-form-item';
import { EzTimepicker } from './ez-timepicker';
import { EzTimepickerConfiguration } from './ez-timepicker.configuration';

@Component({
  selector: 'ez-timepicker',
  templateUrl: './ez-timepicker.component.html',
  styleUrls: ['./ez-timepicker.component.less'],
  providers: [{ provide: EzFormControlComponent, useExisting: EzTimepickerComponent }],
})
export class EzTimepickerComponent extends EzFormControlComponent<EzTimepickerConfiguration, Date>
  implements EzTimepicker, OnInit, OnDestroy {
  constructor(
    protected ezForm: EzFormComponent,
    protected ezFormGroup: EzFormGroupComponent,
    protected ezFormItem: EzFormItemComponent
  ) {
    super(ezForm, ezFormGroup, ezFormItem);
  }

  ngOnInit(): void {
    super.ngOnInit();
  }

  ngOnDestroy(): void {
    super.ngOnDestroy();
  }

  checkConfiguration(configuration: EzFormControlConfiguration): void {}

  defaultDisabledHours: () => number[] = () => {
    if (this.ezFormControlConfiguration.disabledHours) {
      return this.ezFormControlConfiguration.disabledHours(this, this.ezFormGroup, this.ezForm);
    }
    return [];
  };

  defaultDisabledMinutes: (hour: number) => number[] = hour => {
    if (this.ezFormControlConfiguration.disabledMinutes) {
      return this.ezFormControlConfiguration.disabledMinutes(hour, this, this.ezFormGroup, this.ezForm);
    }
    return [];
  };

  defaultDisabledSeconds: (hour: number, minute: number) => number[] = (hour, minute) => {
    if (this.ezFormControlConfiguration.disabledSeconds) {
      return this.ezFormControlConfiguration.disabledSeconds(hour, minute, this, this.ezFormGroup, this.ezForm);
    }
    return [];
  };
}
